package com.boot.config.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Description:自动填充数据库添加时间啊和更新时间
 * @Author: HuangX
 * @Date: 2021/3/25
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.strictInsertFill(metaObject, "createDate", Date.class, new Date());
        this.strictInsertFill(metaObject, "updateDate", Date.class, new Date());
        this.strictInsertFill(metaObject, "deleted", Integer.class,1);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
//        LocalDateTime
        log.info("start update fill ....");
        this.strictUpdateFill(metaObject, "updateDate", Date.class, new Date());
    }
}
